Synchronizing Changes in a File System Which Are Initiated by a Storage Device and a Host Device

ABSTRACT

When a storage device initiates a change in its file system, it locally stores it for future update of the file system. When the host device sends a command to the storage device, the storage device responds to it by commencing a synchronization process during which the two parties coordinate the update of the file system with the stored change. If there are no file system changes pending in the host device, the storage device gets permission from the host device to update the file system with the change and, then, the host device reads the updated file system from the storage device. If there are file system changes pending in the host device, the host device updates a representation of the file system residing in the host device, causes the storage device to make the same changes, and then the storage device initiated change, in the file system. Lastly, the host device receives information from the storage device regarding the changes initiated by the storage device.

FIELD OF THE INVENTION

The present invention generally relates to storage devices and host devices and more specifically to a method for synchronizing a file system used by such devices.

BACKGROUND

Storage devices typically include a non-volatile memory (“NVM”) for storing various types of data, and a memory controller that manages the NVM. The memory controller performs storage operations on the memory (i.e., writing and reading data, etc.) by using a file system that is stored in the NVM. Conventional memory controllers of NVM-based storage devices can make changes to the file system in response to storage commands that they receive from host devices with which they operate, but they cannot initiate changes in the file system independently of the host device. In order for a host device to be able to operate with a storage device, the host device reads information from the storage device, which allows it to locally use a representation of the storage device file system to read data, write data, etc., that is stored in the storage device.

A host device initiates changes in the file system residing in the storage device, for example, when it writes data into the storage device. A storage device may initiate changes in the file system when it performs internal activities such as logging its own activities, storing secure content that is received through an ‘out-of-band’ connection (e.g., ASSD, which is an industry standard connection) that is established between the storage device and a network server, automatically discarding consigned content when user-content is written into the memory of the storage device, moving data or files from one memory partition to another, etc.

If a storage device independently makes changes in its file system, the host device does not necessarily recognize these changes and, therefore, it may inadvertently overwrite them. For example, the host device may overwrite these changes when it writes its own changes into the storage device file system. The file system residing in the storage device and the representation of the file system residing in the host device must be synchronized, regardless of which party initiated changes in the file system, in order to prevent file system inconsistencies. If the file system in the storage device and its representation in the host device are not synchronized, the host device and the storage device cannot function properly.

There is therefore a need to address the problem of de-synchronization of the file system and its representation when the storage device initiates changes in the file system. There is also a need to synchronize changes that are initiated by the storage device and changes that are initiated by the host device to ensure that one coherent file system is used by both parties.

SUMMARY

In view of the foregoing, it would be beneficial to have a storage device and a host device that can efficiently synchronize the file system and the view of the file system. Various embodiments are designed to implement the synchronization, examples of which are provided herein.

To address the foregoing (assuming a storage device is capable of initiating changes in the file system), every time the storage device initiates a change in its file system, which is referred to herein as a “storage device file system”, it locally stores the change for future update of the storage device file system. When the host device sends a storage command or a storage-related command to the storage device, the storage device executes the command and, thereafter, it commences a synchronization process in which the two parties negotiate and coordinate the update of the storage device file system with the one or more pending changes.

If the host device does not initiate changes in the storage device file system (i.e., there are no pending changes in the host device), the synchronization process includes: updating (by the storage device) the storage device file system in the storage device with the changes initiated by the storage device, and—in response to a corresponding command from the host device—transferring to the host device information regarding the changes (i.e., updates) that were made in the storage device file system, in order for the host device to make these changes in the representation of the file system.

If the host device initiates changes in the storage device file system (i.e., there are pending changes in the host device), the synchronization process includes: updating the representation of the file system in the host device, by the host device, with the pending changes; transferring information to the storage device regarding the changes that the host device made in the representation of the file system in order for them to be written into the storage device file system by the storage device, writing the changes into the storage device file system by the storage; and—in response to a corresponding command from the host device—transferring to the host device information regarding the changes that were made in the storage device file system, in order for the host device to make these changes in the representation of the file system.

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated in and constitute part of this specification, illustrate various embodiments with the intent that these examples not be restrictive. It will be appreciated that for simplicity and clarity of the illustration, elements shown in the figures referenced below are not necessarily drawn to scale. Also, where considered appropriate, reference numerals may be repeated among the figures to indicate like, corresponding or analogous elements. Of the accompanying figures:

FIG. 1 is a block diagram of a storage device and a host device according to an embodiment;

FIG. 2 is a method for updating a storage device file system in a storage device according to an embodiment;

FIG. 3 is a method for synchronizing between a storage device file system in a storage device and a representation thereof in a host device according to an embodiment; and

FIG. 4 is a method for synchronizing a storage device file system when a storage device and a host device use a SCSI interface and a SCSI protocol.

DETAILED DESCRIPTION

The description that follows provides various details of example embodiments. However, this description is not intended to limit the scope of the claims but instead to explain various principles of the invention and the manner of practicing it.

As explained above, conventional storage devices cannot (i.e., are not designed to) initiate changes in their file system because their file systems are managed by others (i.e., by their hosts). However, such capability may be imparted to storage devices in the future.

FIG. 1 is a block diagram of a storage device 100 and a host device 140 according to an embodiment. Storage device 100 includes a memory 110 for storing computer files and a storage device file system 112 that facilitates accessing the stored files. Storage device 100 also includes a memory controller 120 for managing memory 110, and a host interface 130. Host interface 130 enables memory controller 120 to exchange data, information, and commands with a host device 140.

Host device 140 includes a host driver 142. Host driver 142 is functionally divided into a file system driver 150 for managing storage device file system 112, and a storage driver 160 for managing the connection between file system driver 150 (and in general between host device 140) and memory controller 120. Host driver 142 holds a representation of storage device file system 112 that allows it, in conjunction with memory controller 120 of storage device 100, to perform storage operations on memory 110 (e.g., write a file into memory 110, read data from memory 100, etc.). The representation of storage device file system 112 is shown at 152.

Storage device file system 112 and its representation (i.e., file system representation 152) have to be (re-)synchronized every time, or once in while (depending on the interaction between the two parties), the storage device and/or the host device initiates one or more changes in the file system because a file system inconsistency results in operation failure of the devices. Therefore, file system inconsistencies must be avoided. By “file system inconsistency” is meant that the storage device file system is not genuinely represented in the host device, in which case the storage device file system and its representation are unsynchronized. By “synchronizing a file system” is, therefore, meant updating the file system with each change that was made in the representation of the file system, and vice versa.

Conventionally, host driver 142 assumes control of file system 112. This means that whenever host driver 142 wants to make a change in storage device file system 112, it makes the storage while taking into account memory considerations such as the size of the free storage space in memory 110, location of free storage areas in memory 110, etc. Host driver 142 gets the information regarding free storage space(s) after it checks out the representation 152 of storage device file system 112. Performing a storage operation in storage device 100 by host driver 142 entails updating file system representation 152 with corresponding changes and, consequently, updating storage device file system 112.

Memory controller 120 may initiate various types of background operations that entail changes in file system 112 that host driver 142 may not be ‘aware of’. Traditionally, in order for host driver 142 to be aware of such changes, host driver 142 has to reread the entire file system 112 from memory 110 in order to update its representation (i.e., representation 152). Other conventional methods for synchronizing storage device file system 112 and its representation in host device 140 (i.e., file system representation 152) would involve resetting host device 140 or storage device 100, or disconnecting the two devices and reconnecting them. These file system synchronization methods are inefficient and, in the event where the two devices are reset or disconnected, data might be corrupted or lost due to the reset or disconnection.

Instead of causing the host device to reread the entire file system, or resetting host device 140 or storage device 100, or disconnecting the two devices and reconnecting them to synchronize the storage device file system and its representation, memory controller 120 defers the changes to be made in file system 112 and, as the changes accumulate, it stores them, on-the-fly, in a log, for example in log 170, in order to make all, or part of them, in the storage device file system at the ‘right’ time, as explained below. Log 170 is a table that includes an entry for each change. Whenever memory controller 120 has another change to make in file system 112, it creates another entry in log 170. By way of example, log 170 contains n entries for accommodating n pending changes that are designated as “Chng 1”, “Chng 2”, “Chng 3”, “Chng 4”, . . . , “Chng n”.

Assume that memory controller 120 decides—independently of host device 140—to store a new, 10 megabytes (“MB”), consigned file in memory 110, which entails a change (which is designated hereinafter as “change-X”) in file system 112. Logging change-X means adding a new log entry to log 170, and storing information in the new log entry regarding, for example, creation of the file (including the file's creation date), the file name (temporarily or permanently) assigned by memory controller 120 to the new file (e.g., “NEWFILE.DAT”), file attributes of the file, pre-allocation of a 10 MB storage space within memory 110 for the file, writing directives for writing the file into memory 110, etc.

Memory controller 120 may temporarily store the content of the 10 MB file in log 170 or external to it, in memory 110 or in random access memory (“RAM”) 180. If memory controller 120 temporarily stores the 10 MB file outside log 170, it stores a pointer in the pertinent entry of log 170, which enables it to locate the file when time comes to write it into memory 110 and to update the file system accordingly. (Note: there is no record in storage device file system 112 for files/data that are temporarily stored in log 170 or elsewhere.) After memory controller 120 makes the change (i.e., after it writes the file into memory 110 and updates file system 112 accordingly), it deletes the file from the storage area that temporarily holds it. Log 170 is held in a storage area (e.g., within memory 110) that is inaccessible to host device 140 in order to prevent the host device from corrupting its content.

If host driver 142 transfers 132 a command to memory controller 120 to perform a storage operation (e.g., reading a data file 114 from storage device 100) and log 170 contains at least one change that is to be made in storage device file system 112, memory controller 120 complies with the command and, then, commences a synchronization process to synchronize between storage device file system 112 and file system representation 152. The synchronization process is elaborated in FIG. 2, which is described below.

Assume that host driver 142 includes a log (i.e., log 154) similar to log 170 of storage device 100, and that log 154 may contain one or more changes, or it may be empty. If host device 140 has pending (i.e., logged) changes that have to be made in file system 112, host driver 142 updates file system representation 152 with the pending changes, and, then, transfers information to memory controller 120 regarding these updates in order for memory controller 120 to update storage device file system 112 with these changes. Situations where host device 140 uses a log such as log 154 are rare. Typically, host driver 142 makes changes to file system representation 152 as it initiates them, without temporarily storing them in a log such as log 154.

By way of example, host driver 150 logs two changes in log 154 (which are designated as “H_chng 1” and “H_chng 2”) in order to make them in file system representation 152. Therefore, before host driver 142 sends to memory controller 120 a corresponding message or command to update file system 112 with the changes logged in log 170 (i.e., “Chng 1”, “Chng 2”, . . . , “Chng n”), it updates file system representation 152 in host device 140 with the two impending changes “H_chng 1” and “H_chng 2”. Then, host driver 142 sends information to memory controller 120 regarding the changes that it recently made in file system representation 152, regardless of whether (the) changes were logged in a log such as log 154 or not. Then, memory controller 120 updates storage device file system 112 with the changes initiated by file system driver 150 (e.g., “H_chng 1” and “H_chng 2”), and, thereafter, with the changes, or some of them, initiated by memory controller 120 and temporarily held in log 170.

Then, storage device 100 notifies host driver 142 that storage device file system 112 is updated with all the changes initiated so far by both parties. Host driver 142 responds to the memory controller's notification by requesting information from memory controller 120 that pertains to the changes that were initiated by memory controller 120, in order to update file system representation 152 with these changes so that file system representation 152 and storage device file system 112 be synchronized.

If memory controller 120 notifies host driver 142 that it has changes to make in storage device file system 112 (i.e., log 170 contains one or more changes) and host driver 142 did not make new changes in file system representation 152 since the last synchronization nor there are pending changes in log 154, host driver 142 sends a corresponding message or command to memory controller 120 to update storage device file system 112 with the changes pending in storage device 100. Then, host driver 142 requests information from memory controller 120 regarding the changes that memory controller 120 made in storage device file system 112, in order to update file system representation 152 with the same changes.

FIG. 2 is a method for updating a storage device file system with changes initiated by a storage device according to an embodiment. FIG. 2 will be described in association with FIG. 1. At step 210, memory controller 120 initiates a change in storage device file system 112. As explained above, changes in the storage device's file system have to be made also in the representation 152 of the storage device file system 112 in order to synchronize them. Traditionally, storage devices, such as storage device 100, react to commands that they receive from host devices such as host device 140 but they do not initiate communications with their host. Therefore, at step 210, rather than immediately notifying host device 140 of the change and/or making the change in storage device file system 112, memory controller 120 stores the change in log 170, at step 220, and waits until host device 140 addresses it (i.e., sends to it a message or command).

At step 230, if memory controller 120 does not receive any message or command from host device 140 (shown as “N” at step 230) and, in addition, at step 240 it does not initiate another change in storage device file system 112 (shown as “N” at step 240), memory controller 120 waits, at step 230, for a host message or command.

At step 230, if memory controller 120 does not receive any message or command from host device 140 (shown as “N” at step 230) and, while waiting for such a message or command, it initiates another change in storage device file system 112 (shown as “Y” at step 240), memory controller 120 stores, at step 220, the additional change in log 170.

If at step 230 memory controller 120 receives a message or command from host device 140 (shown as “Y” at step 230), memory controller 120 sends, at step 250, a notification to host driver 142 regarding the initiated, yet pending, change(s). Contingent on a message or command that memory controller 120 receives from host driver 142 at step 260 to make the change(s), memory controller 120 makes the change(s) in storage device file system 112 at step 270. While memory controller 120 makes a particular change in storage device file system 112, it defers other changes from taking place. In other words, it makes all the changes, or only some of them, one at a time and according to a predefined order, and/or contingent on preceding changes or succeeding changes.

At step 280, memory controller 120 notifies host driver 142 that storage device file system 112 has changed such that representation 152 of storage device file system 112 on host device 140 can be updated with this (or these) change (or changes).

As explained above, host driver 142 may also initiate changes in storage device file system 112. Therefore, if there are changes that host driver 142 schedules to make in storage device file system 112, it makes these changes in file system representation 152 and notifies memory controller 120 of these changes prior to memory controller 120 making its own changes (i.e., the changes logged in log 170), as is more elaborated in FIG. 3, which is described below.

FIG. 3 is a method for synchronizing between a storage device file system in a storage device and a representation thereof in a host device according to an embodiment. FIG. 3 will be described in association with FIG. 1 and FIG. 2. At step 310, host driver 142 receives a notification from memory controller 120 regarding a change, or changes, in storage device file system 112 that memory controller 120 initiates (this step corresponds to step 250 in FIG. 2). Assume that the change(s) initiated by memory controller 120 is/are temporarily stored in log 170. If host driver 142 does not initiate changes of its own in storage device file system 112 (shown as “N” at step 320), then, in response to receiving the notification from memory controller 120, host driver 142 sends, at step 350, a (‘go ahead’) message or command to memory controller 120 to make the changes logged in log 170 in storage device file system 112.

At step 360, which corresponds to step 280 in FIG. 2, host driver 142 receives a notification from memory controller 120 that it changed storage device file system 112 in storage device 100. Then, at step 370, host driver 142 updates file system representation 152 based on information that it requests and receives from memory controller 120, which pertains to the change(s) made by memory controller 120 in storage device file system 112.

FIG. 4 is a method for synchronizing file systems when storage device 100 and host device 140 use SCSI interface and SCSI protocol. FIG. 4 will be described in association with FIG. 1. Small computer system interface (“SCSI”) standards define commands, protocols, and electrical and optical interfaces for physically connecting and transferring data between computers and peripheral devices. SCSI can be used to connect a wide range of devices, for example storage device 100 and host device 140. Assume that log 170 contains changes that have to be made in the storage device file system.

At step 410, storage device 100 waits to receive a command (e.g., memory sector read or write) from host device 140. Upon receiving the command, storage device 100 executes the command and, then, returns to host device 140, at step 420, a “check condition” indication that indicates to host device 140 that a potential error condition occurred.

Responsive to host device 140 receiving the “check condition” indication, host device 140 gets from storage device 100, at step 430, a “sense code” corresponding to the error condition, and another sense code that indicates that, while the command was successfully executed, storage device 100 has initiated changes in the storage device file system, and that these changes are currently pending. The two SCSI sense codes mentioned above are unconventional codes (i.e., they are new types of codes).

In the SCSI scheme, a “SCSI Status Code” is used to determine the success or failure of a SCSI command. At the end of a command, the target device (e.g., storage device 100) returns a Status Code byte which can conventionally be, for example, “00 h OK” (“h” means “hexadecimal”), which indicates that the device (e.g., storage device 100) has completed the task successfully; “02 h Check condition”, which is an indication from the target that an error occurred when it attempted to execute a SCSI command, etc. The initiator (e.g., host device 140) usually issues a SCSI Request Sense command in order to obtain a Key Code Qualifier (“KCQ”) from the target device. Key Code Qualifier (KCQ) is a computer term used to describe an error-code that is returned by a SCSI device. When a SCSI target device returns a “check condition” in response to a command, the initiator usually issues a SCSI Request Sense command. The target device responds to the Request Sense command with a set of SCSI sense data that contain information about the error (i.e., sense key, sense code (ASC), and sense code qualifier (ASCQ)).

The process of returning a “check condition” indication to host device 140 and getting sense codes from storage device 100 may be repeated for each successive read/write command until host device 140 sends to storage device 100, at step 440, a “commit file system changes” command, which is a new type of SCSI command (i.e., it is an unconventional SCSI command).

Responsive to storage device 100 receiving the commit file system changes command from host device 140, storage device 100 enters, at step 450, a “busy” state, as it is occupied making the change or changes, and sends a “busy” message to host device 140 prior to or while updating the storage device file system with the pending change(s). Storage device 100 may send the “busy” message to host device 140 intermittently or each time host device 140 sends a command to storage device 100 and memory controller 120 has not yet finished making the changes logged in log 170 in the storage device file system. With respect to the SCSI scheme, the target (a storage device such as storage device 100) enters a “busy” state (SCSI status code “08 h”) and returns a “busy” message if it cannot complete a command at that time, for example because it is in a condition known as the contingent allegiance condition. On a SCSI connection, a “contingent allegiance condition” occurs while a SCSI device reports an error. Other connection schemes may use SCSI-like or different methods to handle a “busy” condition and to report an error to the host device.

While in the “busy” state, storage device 100 updates the storage device file system with a pending change, defer other changes while it updates the file system with the change, and refrains from executing (i.e., it ignores) additional storage commands while the “busy” state prevails in order not to interfere with the file system updating process that is taking place in storage device 100.

While the file system updating process is in progress in storage device 100, storage device 100 writes, at step 460, all or some of the logged changes into the storage device file system in storage device 100 in sequence until the content of log 170 is fully exhausted. Memory controller 120 reviews the logged changes and, based on the review, decides which changes of all the logged changes should be written in the file system. (Note: a logged change may cancel out another change or a series of changes.) Then, memory controller 120 makes the (selected) changes in the file system according to the order at which they were logged (i.e., ‘first logged first made’).

Memory controller 120 may update storage device file system 112 with deferred (i.e., pending) changes according to a predetermined order of preceding changes and succeeding changes, or contingent on such changes. For example, if a first change involves writing some data in the file system and a fifth change involves deleting that data from the file system, memory controller 120 discards these changes because they cancel out each other.

After storage device 100 makes all the relevant changes in the file system, it notifies host device 140, at step 470, that the commit file system changes command was successfully executed. In response to the notification, host device 140 (i.e., host driver 142) rescans all the file system structures within storage device 100 by sending corresponding read command(s) to storage device 100. Storage device 100 responds to the read command(s) issued by host driver 142 by transferring the requested information, at step 480, to host device 140.

Memory controller 120 and/or host driver 142 can be a standard off-the-shelf System-on-Chip (“SoC”) device or a System-in-Package (“SiP”) device or general purpose processing unit with specialized software or application (e.g., application 112 and application 156, respectively) that, when executed by memory controller 120, or by host driver 142, performs the processes, steps, operations, and determinations described herein. Alternatively, memory controller 120 and/or host driver 142 can be an Application-Specific Integrated Circuit (“ASIC”) that implements the processes, steps, operations, and determinations described herein by using hardware.

The articles “a” and “an” are used herein to refer to one or to more than one (i.e., to at least one) of the grammatical object of the article, depending on the context. By way of example, depending on the context, “an element” can mean one element or more than one element. The term “including” is used herein to mean, and is used interchangeably with, the phrase “including but not limited to”. The terms “or” and “and” are used herein to mean, and are used interchangeably with, the term “and/or,” unless context clearly indicates otherwise. The term “such as” is used herein to mean, and is used interchangeably, with the phrase “such as but not limited to”.

Note that the foregoing is relevant to various types of mass storage devices such as memory cards, SD-driven flash memory cards, flash storage devices, “Disk-on-Key” devices that are provided with a Universal Serial Bus (“USB”) interface, USB Flash Drives (“UFDs”), MultiMedia Card (“MMC”), Secure Digital (“SD”), miniSD and micro SD, and so on.

Having thus described exemplary embodiments of the invention, it will be apparent to those skilled in the art that modifications of the disclosed embodiments will be within the scope of the invention. Alternative embodiments may therefore include more modules, fewer modules and/or functionally equivalent modules. Hence the scope of the claims that follow is not limited by the disclosure herein. 

1. A method of updating a file system with changes initiated by a storage device, the method comprising: in a storage device having a memory and a memory controller, wherein the memory stores a storage device file system, performing by the memory controller, initiating a change in the storage device file system; notifying a host device of the initiated change and, contingent on a message received from the host device, making the change in the storage device file system, wherein while making the change, deferring other changes from taking place; and notifying the host device that the storage device file system has changed such that a representation of the storage device file system on the host device can be updated with such change.
 2. The method as in claim 1, wherein the notification regarding the initiated change is sent to the host device in response to receiving a storage command or a storage-related command from the host device.
 3. The method as in claim 1, further comprising entering a “busy” state while making the change, and ignoring additional storage commands from the host device while the “busy” state prevails.
 4. The method as in claim 1, further comprising returning a “busy” message to the host device in response to a command received from the host device prior to or while updating the storage device file system with the change.
 5. The method as in claim 1, wherein initiating the change in the storage device file system includes logging the change in a memory area within the memory which is inaccessible to the host device.
 6. The method as in claim 1, wherein the notifying to the host device that the storage device file system has changed causes the host device to update the representation of the storage device file system with the change.
 7. The method as in claim 1, wherein the storage device file system is updated with the change according to a predetermined order of preceding changes and/or succeeding changes.
 8. The method as in claim 1, wherein the storage device file system is updated with the change contingent on other changes.
 9. The method as in claim 1, wherein updating the storage device file system with the change is performed after the representation of the storage device file system in the host device is updated with a change initiated by the host device.
 10. A storage device connectable to a host device, comprising: a memory for storing a storage device file system; a memory controller for managing the memory, wherein the memory controller is configured, to initiate a change in the storage device file system; to notify a host device of an initiated change and, contingent on a message received from the host device, to make the change in the storage device file system, and, while making the change, to defer other changes from taking place; and to notify the host device that the storage device file system has changed such that a representation of the storage device file system on the host device can be updated with the change.
 11. The storage device as in claim 10, wherein the memory controller sends the notification regarding the initiated change to the host device in response to receiving a storage command or a storage-related command from the host device.
 12. The storage device as in claim 10, wherein the memory controller is further configured to return a “busy” message to the host device in response to a storage command or storage-related command that it receives from the host device prior to updating the storage device file system with the change.
 13. The storage device as in claim 10, wherein prior to making the change the memory controller logs the change in a memory area within the memory which is inaccessible to the host device.
 14. The storage device as in claim 10, wherein the memory controller enters a “busy” state while making the change, and wherein the memory controller ignores additional storage commands from the host device while it is in the “busy” state.
 15. The storage device as in claim 10, wherein the memory controller is further configured to return a “busy” message to the host device in response to a storage request or storage-related request that the memory controller receives from the host device prior to or while updating the storage device file system with the change.
 16. The storage device as in claim 10, wherein by sending the notification to the host device that the storage device file system has changed, the memory controller causes the host device to update the representation of the storage device file system with the change.
 17. The storage device as in claim 10, wherein the memory controller updates the storage device file system with the change according to a predetermined order of preceding changes and/or succeeding changes.
 18. The storage device as in claim 10, wherein the memory controller updates the storage device file system with the change contingent on other changes.
 19. The storage device as in claim 10, wherein the memory controller updates the storage device file system with the change after the representation of the storage device file system in the host device is updated with a change initiated by the host device.
 20. The storage device as in claim 10, wherein the memory controller logs the deferred change in a memory area inaccessible to the host device. 